<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>主页顶部菜单</title>
	<link rel="shortcut icon" href="favicon.ico">
	<link rel="stylesheet" href="css/iconfont.css">
	<link rel="stylesheet" href="css/global.css">
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<link rel="stylesheet" href="css/bootstrap-theme.min.css">
	<link rel="stylesheet" href="css/swiper.min.css">
	<link rel="stylesheet" href="css/styles.css">
	<link rel="stylesheet" href="css/yangshi.css" />
	<script type="text/javascript" src="layui/layui.js" charset="utf-8"></script>

	
	</head>
	
	<body>
		<div class="tab-header">
		<div class="inner">
			<div class="pull-left">

				<div class="pull-left" id="up_left">嗨!<span class="cr" id="username">XXX</span></div>

			
			</div>
			<div class="pull-right" id="up_right">

				
			</div>
		</div>
	</div>
	</body>
	
	
	<script src="js/jquery.1.12.4.min.js"></script>
	<script>
		selects();
		
		function selects(){
			$.ajax({
    			type:"get",
    			url:"http://localhost:16111/memurbac/reachbytypeidmemu",
    			dataType:"json", 
    			xhrFields:{withCredentials: true},
    			data:{typeid:1},
    			success:function(res){
    				//表示更改状态成功
    				if(res.code==200){
    					
    			    	//将数据添加到table中
    					for(var i in res.data.childMemu){
    						var data=res.data;
                          if(getCookie("userid")!=null&&getCookie("userid")!=""){
                           	
                           	              
                        if(data.childMemu[i].memu_name==="登录"){
                      		
                 $.ajax({
					url: 'http://localhost:16111/user/selectmydata',
					type: 'get',
					dataType: 'json',
					data:{userid:getCookie("userid")},
					success: function(data) {
						
							$('#username').html(data.userData.user_name);
					}
				});
                        		
                        	
                        		var str="<a  onclick=\"rest()\"><span class=\"cr\">退出登录</span></a>"
                        	}else{
                        		var str="<a href=\""+data.childMemu[i].memu_logurl+"\">"+data.childMemu[i].memu_name+"</a>";
                        	}
                        	
                        	
                        	
                          }else{
                          	
                          	var str="<a href=\""+data.childMemu[i].memu_url+"\">"+data.childMemu[i].memu_name+"</a>";
                          }
                           
                           
             
                    

			  
	 			        if(i<2){       	
	 			         $('#up_left').html($('#up_left').html()+str);	
				        }else{
	 			          $('#up_right').html($('#up_right').html()+str);
	 			        }
  	
                     
   }
    			    
    			    	
    			    	
    			    	
    
    				}else{
    					
    					layui.use("layer", function () {
                //提示错误信息
    					layer.msg(res.error,{icon:7,time:1000});
             })

    					
    				
    				}
    			},
    			error:function(error){
    			
    				layui.use("layer", function (){
             	//提示错误信息
    				layer.msg(JSON.stringify(error),{icon:2,time:1000});
             })
    				
    			}
    				
    		});
               
		}
		     	//退出登录,
      function	rest(){
          
      	
      	//清除token
     	 document.cookie="token=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=localhost";
     	 //清除token
     	 document.cookie="userid=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=localhost";
     		
     	//刷新本页面
     	location.reload();
     	}
      
      
      function getCookie(cookieName) {
			var strCookie = document.cookie;
			var arrCookie = strCookie.split("; ");
			for(var i = 0; i < arrCookie.length; i++) {
				var arr = arrCookie[i].split("=");
				if(cookieName == arr[0]) {
					return arr[1];
				}
			}
			return "";
		}
	</script>
</html>
